import request from '@/utils/request_axios'

/**
 * 添加一个用户组
 * @param {Object} data
 * @returns
 */
export function addAuthGroupItem(data) {
  let method = data.id ? 'PUT' : 'POST'
  return request({
    url: '/sys/role',
    method: method,
    data
  })
}

/**
 * 编辑一个用户组
 * @param {Object} data
 * @returns
 */
export function updateAuthGroupItem(data) {
  return request({
    url: '/sys/role',
    method: 'PUT',
    data
  })
}

/**
 * 获取一个用户组
 * @param {Number} id
 * @returns
 */
export function getAuthGroupItem(id) {
  return request({
    url: '/sys/role',
    method: 'GET',
    show: true,
    data: {
      id: id
    }
  })
}

/**
 * 删除一个用户组
 * @param {Number} group_id
 * @returns
 */
export function delAuthGroupItem(group_id) {
  return request({
    url: '/sys/role',
    method: 'DELETE',
    show: true,
    data: { id: group_id }
  })
  // return request('DELETE', '/sys/roles/id', { id: group_id })
}

/**
 * 获取用户组列表 -- 分页
 * @param {Object} data
 * @returns
 */
export function getAuthGroupListPage(data) {
  return request({
    url: '/sys/role',
    method: 'GET',
    data
  })
  // return request('GET', '/sys/roles/page', data)
}

/**
 * 获取用户组列表 -- 不分页
 * @param {Object} data
 * @returns
 */
export function getAuthGroupList(data) {
  return request({
    url: '/sys/role/all',
    method: 'GET',
    data
  })
}

/**
 * 批量设置用户组状态
 * @param {Array} group_id
 * @param {Number} status
 * @returns
 */
export function setAuthGroupStatus(group_id, status) {
  return request({
    url: '/v1/auth_group',
    method: 'post',
    params: {
      method: 'set.auth.group.status'
    },
    data: {
      group_id,
      status
    }
  })
}

/**
 * 设置用户组排序值
 * @param {Number} group_id
 * @param {Number} sort
 * @returns
 */
export function setAuthGroupSort(group_id, sort) {
  return request({
    url: '/v1/auth_group',
    method: 'post',
    params: {
      method: 'set.auth.group.sort'
    },
    data: {
      group_id,
      sort
    }
  })
}
